package com.masterclient.app.businessmodule.homemodule.view.listenerimpl;

import android.graphics.Color;

import com.masterclient.app.businessmodule.homemodule.presenter.IHomePresenter;
import com.masterclient.app.businessmodule.homemodule.view.IHomeMainView;
import com.masterclient.app.businessmodule.homemodule.view.adapter.HomeRecycleAdapterGroupListener;
import com.masterclient.app.businessmodule.homemodule.view.adapter.top.HomeTopComponentListener;

public class HomeViewEventListenerImpl implements HomeRecycleAdapterGroupListener, HomeTopComponentListener {

    private IHomePresenter iHomePresenter;
    private IHomeMainView iHomeMainView;

    public HomeViewEventListenerImpl bindPresenterAndInteraction(IHomePresenter iHomePresenter, IHomeMainView iHomeMainView) {
        this.iHomePresenter = iHomePresenter;
        this.iHomeMainView = iHomeMainView;
        return this;
    }

    /////////////////////////////////////////////////////////////////////////////////
    //
    //                    HomeRecycleAdapterGroupListener
    //
    /////////////////////////////////////////////////////////////////////////////////
    @Override
    public void homeAdapterToBannerColorChange(int color) {
        if (iHomeMainView != null) {
//            iHomeMainView.mainToolBar().setBackgroundColor(color);
            iHomeMainView.myRefreshHead().changeBackColor(Color.parseColor("#ffffff"));
            iHomeMainView.myRefreshHead().changeTextColor(Color.parseColor("#ffffff"));
//            Drawable drawable = iHomeMainView.mainToolBar().getBackground();
//            if (drawable != null) {
//                drawable.mutate().setAlpha(255 - iHomeMainView.viewHelper().getAlphaFloat());
//            }
        }
    }

    @Override
    public void homeAdapterToSaleTabEvents(String type, String productId, String mapId, int childPosition, String startTime) {
        if (iHomePresenter != null) {
            iHomePresenter.interactionSale(type,productId,mapId,childPosition,startTime);
        }
    }

    @Override
    public void homeAdapterToClickSaleTab(String mapId, int childPosition,String status) {
        if (iHomePresenter != null) {
            iHomePresenter.serviceSaleDatas(mapId,childPosition);
        }
    }

    @Override
    public void homeAdapterToClickFooterTab(int index) {
        if (iHomePresenter != null) {
            iHomePresenter.serviceFooterNewShopDataLoadMore(index,false);
        }
    }

    @Override
    public void homeAdapterToRefreshSale() {
        if (iHomePresenter != null) {
            iHomePresenter.serviceApiHomeDataOnlyToSale();
        }
    }

    /////////////////////////////////////////////////////////////////////////////////
    //
    //                    HomeTopComponentListener
    //
    /////////////////////////////////////////////////////////////////////////////////

    @Override
    public void homeTopToQrClick() {
        if (iHomePresenter != null) {
            iHomePresenter.interactionToOpenQrPage();
        }
    }

    @Override
    public void homeTopToSearchClick() {
        if (iHomePresenter != null) {
            iHomePresenter.interactionSearchPage();
        }
    }

    @Override
    public void homeTopToMessageClick() {
        if (iHomePresenter != null) {
            iHomePresenter.interactionToOpenMessagePage();
        }
    }

    @Override
    public void homeTopToSignClick() {
        if (iHomePresenter != null) {
            iHomePresenter.serviceApiSign();
        }
    }
}
